package com.kantboot.system.dict.web.controller;

import com.kantboot.system.dict.domain.dto.GlobalTranslateDTO;
import com.kantboot.system.dict.domain.dto.SysDictI18nDTO;
import com.kantboot.system.dict.service.ISysDictI18nService;
import com.kantboot.util.common.result.RestResult;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 系统字典控制层
 */
@RestController
@RequestMapping("/system-dict-web/dictI18n")
public class SysDictI18nController {

    @Resource
    private ISysDictI18nService service;

    /**
     * 根据字典分组和语言编码查询字典国际化Map
     */
    @RequestMapping("/getDictI18nMap")
    public RestResult<Map<String,String>> getDictI18nMap(
            @RequestParam("dictGroupCode") String dictGroupCode,
            @RequestParam("languageCode") String languageCode){
        return RestResult.success(
                service.getDictI18nMap(dictGroupCode,languageCode),
                "getSuccess", "获取成功");
    }

    /**
     * 根据字典分组查询字典国际化Map
     */
    @RequestMapping("/getDictI18nMapSelf")
    public RestResult<Map<String,String>> getDictI18nMapSelf(
            @RequestParam("dictGroupCode") String dictGroupCode){
        return RestResult.success(
                service.getDictI18nMapSelf(dictGroupCode),
                "getSuccess", "获取成功");
    }

    /**
     * 根据字典编码、字典分组编码和语言编码查询值
     */
    @RequestMapping("/getValue")
    public RestResult<String> getValue(
            @RequestParam("dictCode") String dictCode,
            @RequestParam("dictGroupCode") String dictGroupCode,
            @RequestParam("languageCode") String languageCode){
        return RestResult.success(
                service.getValue(dictCode,dictGroupCode,languageCode),
                "getSuccess", "获取成功");
    }

    /**
     * 保存字典和字典国际化
     */
    @RequestMapping("/saveDictAndDictI18n")
    public RestResult<Void> saveDictAndDictI18n(@RequestBody SysDictI18nDTO entity){
        service.saveDictAndDictI18n(entity);
        return RestResult.success(null, "getSuccess", "获取成功");
    }

    /**
     * 全局翻译
     */
    @RequestMapping("/globalTranslate")
    public RestResult<Void> globalTranslate(@RequestBody GlobalTranslateDTO dto){
        service.globalTranslate(dto);
        return RestResult.success(null, "getSuccess", "获取成功");
    }

}
